package com.yhb.service.impl;

import com.yhb.conf.ResultCode;
import com.yhb.service.InviteCodeService;
import me.edzh.spring.bootstrap.common.GlobalPropertiesConfigurer;
import me.edzh.spring.bootstrap.utils.exception.ServiceException;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import javax.annotation.PostConstruct;
import java.util.List;

@Service
public class InviteCodeServiceImpl implements InviteCodeService {

    @Autowired
    private RedisTemplate<String, String> redis;

    @Override
    public String getInviteCode() {
        String result = redis.boundListOps("inviteCode").rightPop();
        if (result == null) {
            throw new ServiceException(ResultCode.ERROR_INVITE_CODE_GENERATION, "邀请码生成错误");
        }

        return result;
    }
}
